home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Add-Ons
/
4D
/
ComboBox 1.1.1
/
src
/
ComboBoxCmds.c
< prev
next >
Wrap
Text File
|
1996-02-23
|
18KB
|
647 lines
//---------------------------------------------------------------------------------------
//
// ComboBoxCmds.c -- Source for ComboBox external area's supporting commands
//
// Copyright ©1995-1996, Pensacola Christian College
//
// ======================================================================
// Change History
// ======================================================================
//
// 1.0 08/ /95 Steve Dwire
// Initial release
//
//---------------------------------------------------------------------------------------
#include <Ext4D.h>
#include "ComboBoxMain.h" // Include your header here.
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetDefTxtFnt
//
//---------------------------------------------------------------------------------
void CB_SetDefTxtFnt(PackHnd PackDataHnd, SWORD FontNum, SWORD FontSize, SWORD FontStyle)
{
(*PackDataHnd)->DefTextFont = FontNum;
(*PackDataHnd)->DefTextSize = FontSize;
(*PackDataHnd)->DefTextStyle = FontStyle;
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetDefTxtCol
//
//---------------------------------------------------------------------------------
void CB_SetDefTxtCol(PackHnd PackDataHnd, SWORD ForeColor, SWORD BackColor)
{
(*PackDataHnd)->DefTextFGColor = ForeColor;
(*PackDataHnd)->DefTextBGColor = BackColor;
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetDefLstFnt
//
//---------------------------------------------------------------------------------
void CB_SetDefLstFnt(PackHnd PackDataHnd, SWORD FontNum, SWORD FontSize, SWORD FontStyle)
{
(*PackDataHnd)->DefListFont = FontNum;
(*PackDataHnd)->DefListSize = FontSize;
(*PackDataHnd)->DefListStyle = FontStyle;
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetDefLstCol
//
//---------------------------------------------------------------------------------
void CB_SetDefLstCol(PackHnd PackDataHnd, SWORD ForeColor, SWORD BackColor)
{
(*PackDataHnd)->DefListFGColor = ForeColor;
(*PackDataHnd)->DefListBGColor = BackColor;
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetDefLstRws
//
//---------------------------------------------------------------------------------
void CB_SetDefLstRws(PackHnd PackDataHnd, SWORD Rows)
{
(*PackDataHnd)->DefListRows = Rows;
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetDefPopPic
//
//---------------------------------------------------------------------------------
void CB_SetDefPopPic(PackHnd PackDataHnd, SWORD CUp, SWORD CDown, SWORD CDis, SWORD MUp, SWORD MDown, SWORD MDis)
{
(*PackDataHnd)->DefCPICTResUp = CUp;
(*PackDataHnd)->DefCPICTResDn = CDown;
(*PackDataHnd)->DefCPICTResDis = CDis;
(*PackDataHnd)->DefMPICTResUp = MUp;
(*PackDataHnd)->DefMPICTResDn = MDown;
(*PackDataHnd)->DefMPICTResDis = MDis;
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetDefGap
//
//---------------------------------------------------------------------------------
void CB_SetDefGap(PackHnd PackDataHnd, SWORD Pict, SWORD Top, SWORD Left, SWORD Right)
{
(*PackDataHnd)->DefPixGap = Pict;
(*PackDataHnd)->DefTopGap = Top;
(*PackDataHnd)->DefLeftGap = Left;
(*PackDataHnd)->DefRightGap = Right;
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetDefLead
//
//---------------------------------------------------------------------------------
void CB_SetDefLead(PackHnd PackDataHnd, SWORD Lead)
{
(*PackDataHnd)->DefPixLead = Lead;
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetDefFlags
//
//---------------------------------------------------------------------------------
void CB_SetDefFlags(PackHnd PackDataHnd, SWORD CanFind, SWORD CanFill, SWORD CanList, SWORD CanEdit, SWORD ListOnActivate, SWORD ListOnKeystroke)
{
(*PackDataHnd)->DefFlags.CanFind = (CanFind != 0);
(*PackDataHnd)->DefFlags.CanFill = (CanFill != 0);
(*PackDataHnd)->DefFlags.CanList = ((CanList || ListOnActivate || ListOnKeystroke) != 0);
(*PackDataHnd)->DefFlags.CanEdit = (CanEdit != 0);
(*PackDataHnd)->DefFlags.ListOnActivate = (ListOnActivate != 0);
(*PackDataHnd)->DefFlags.ListOnKeystroke = (ListOnKeystroke != 0);
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetTxtFnt
//
//---------------------------------------------------------------------------------
void CB_SetTxtFnt(AreaHnd AreaDataHnd, SWORD FontNum, SWORD FontSize, SWORD FontStyle)
{
TEHandle text;
(*AreaDataHnd)->TextFont = FontNum;
(*AreaDataHnd)->TextSize = FontSize;
(*AreaDataHnd)->TextStyle = FontStyle;
text = (*AreaDataHnd)->TextTEHnd;
(*text)->txFont = FontNum;
(*text)->txSize = FontSize;
(*text)->txFace = FontStyle;
InvalRect(&((*AreaDataHnd)->AreaRect));
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetTxtCol
//
//---------------------------------------------------------------------------------
void CB_SetTxtCol(AreaHnd AreaDataHnd, SWORD ForeColor, SWORD BackColor)
{
(*AreaDataHnd)->TextFGColor = ForeColor;
(*AreaDataHnd)->TextBGColor = BackColor;
InvalRect(&((*AreaDataHnd)->AreaRect));
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetLstFnt
//
//---------------------------------------------------------------------------------
void CB_SetLstFnt(AreaHnd AreaDataHnd, SWORD FontNum, SWORD FontSize, SWORD FontStyle)
{
AreaPtr AreaDataPtr;
HLock((Handle)AreaDataHnd);
AreaDataPtr = *AreaDataHnd;
AreaDataPtr->ListFont = FontNum;
AreaDataPtr->ListSize = FontSize;
AreaDataPtr->ListStyle = FontStyle;
RedrawList(AreaDataPtr);
HUnlock((Handle)AreaDataHnd);
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetLstCol
//
//---------------------------------------------------------------------------------
void CB_SetLstCol(AreaHnd AreaDataHnd, SWORD ForeColor, SWORD BackColor)
{
AreaPtr AreaDataPtr;
HLock((Handle)AreaDataHnd);
AreaDataPtr = *AreaDataHnd;
AreaDataPtr->ListFGColor = ForeColor;
AreaDataPtr->ListBGColor = BackColor;
RedrawList(AreaDataPtr);
HUnlock((Handle)AreaDataHnd);
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetLstRws
//
//---------------------------------------------------------------------------------
void CB_SetLstRws(AreaHnd AreaDataHnd, SWORD Rows)
{
AreaPtr AreaDataPtr;
HLock((Handle)AreaDataHnd);
AreaDataPtr = *AreaDataHnd;
AreaDataPtr->ListRows = Rows;
CalcListRect(AreaDataPtr);
//••••• RESIZE THE WINDOW IF IT'S OPEN
RedrawList(AreaDataPtr);
HUnlock((Handle)AreaDataHnd);
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_GetLstRws
//
//---------------------------------------------------------------------------------
SLONG CB_GetLstRws(AreaHnd AreaDataHnd)
{
return (*AreaDataHnd)->ListRows;
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetPopPic
//
//---------------------------------------------------------------------------------
void CB_SetPopPic(AreaHnd AreaDataHnd, SWORD CUp, SWORD CDown, SWORD CDis, SWORD MUp, SWORD MDown, SWORD MDis)
{
AreaPtr AreaDataPtr;
HLock((Handle)AreaDataHnd);
AreaDataPtr = *AreaDataHnd;
AreaDataPtr->CPICTResUp = CUp;
AreaDataPtr->CPICTResDn = CDown;
AreaDataPtr->CPICTResDis = CDis;
AreaDataPtr->MPICTResUp = MUp;
AreaDataPtr->MPICTResDn = MDown;
AreaDataPtr->MPICTResDis = MDis;
InitAreaPICT(AreaDataPtr);
CalcTextRect(AreaDataPtr);
InvalRect(&(AreaDataPtr->AreaRect));
HUnlock((Handle)AreaDataHnd);
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetGap
//
//---------------------------------------------------------------------------------
void CB_SetGap(AreaHnd AreaDataHnd, SWORD Pict, SWORD Top, SWORD Left, SWORD Right)
{
AreaPtr AreaDataPtr;
HLock((Handle)AreaDataHnd);
AreaDataPtr = *AreaDataHnd;
AreaDataPtr->PixGap = Pict;
AreaDataPtr->TopGap = Top;
AreaDataPtr->LeftGap = Left;
AreaDataPtr->RightGap = Right;
CalcTextRect(AreaDataPtr);
CalcListRect(AreaDataPtr);
InvalRect(&(AreaDataPtr->AreaRect));
HUnlock((Handle)AreaDataHnd);
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetLead
//
//---------------------------------------------------------------------------------
void CB_SetLead(AreaHnd AreaDataHnd, SWORD Lead)
{
(*AreaDataHnd)->PixLead = Lead;
HLock((Handle)AreaDataHnd);
CalcTextRect(*AreaDataHnd);
HUnlock((Handle)AreaDataHnd);
InvalRect(&((*AreaDataHnd)->AreaRect));
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetFlags
//
//---------------------------------------------------------------------------------
void CB_SetFlags(AreaHnd AreaDataHnd, SWORD CanFind, SWORD CanFill, SWORD CanList, SWORD CanEdit, SWORD ListOnActivate, SWORD ListOnKeystroke)
{
(*AreaDataHnd)->Flags.CanFind = (CanFind != 0);
(*AreaDataHnd)->Flags.CanFill = (CanFill != 0);
(*AreaDataHnd)->Flags.CanList = ((CanList || ListOnActivate || ListOnKeystroke) != 0);
(*AreaDataHnd)->Flags.CanEdit = (CanEdit != 0);
(*AreaDataHnd)->Flags.ListOnActivate = (ListOnActivate != 0);
(*AreaDataHnd)->Flags.ListOnKeystroke = (ListOnKeystroke != 0);
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_FillLst
//
//---------------------------------------------------------------------------------
void CB_FillLst(AreaHnd AreaDataHnd, UBYTE* ListArrName)
{
// For Windows compatibility, interprocess variables can
// start with '◊' (InterProcChar) or '<>'.
if((((SBYTE*)ListArrName)[1]) == InterProcChar)
{
(*AreaDataHnd)->Flags.InterprocArr = true;
(*AreaDataHnd)->ListArrName[0] = ListArrName[0]-1;
BlockMove(&(((SBYTE*)ListArrName)[2]),&(((SBYTE*)((*AreaDataHnd)->ListArrName))[1]),(*AreaDataHnd)->ListArrName[0]);
}
else if (((((SBYTE*)ListArrName)[1]) == '<') && (*((char*)ListArrName+2) == '>'))
{
(*AreaDataHnd)->Flags.InterprocArr = true;
(*AreaDataHnd)->ListArrName[0] = ListArrName[0]-2;
BlockMove(&(((SBYTE*)ListArrName)[3]),&(((SBYTE*)((*AreaDataHnd)->ListArrName))[1]),(*AreaDataHnd)->ListArrName[0]);
}
else
{
(*AreaDataHnd)->Flags.InterprocArr = false;
BlockMove(ListArrName,(*AreaDataHnd)->ListArrName,ListArrName[0]+1);
}
CB_UpdateLst(AreaDataHnd);
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_UpdateLst
//
//---------------------------------------------------------------------------------
void CB_UpdateLst(AreaHnd AreaDataHnd)
{
HLock((Handle)AreaDataHnd);
ListSynchronize(*AreaDataHnd);
HUnlock((Handle)AreaDataHnd);
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetLstPos
//
//---------------------------------------------------------------------------------
void CB_SetLstPos(AreaHnd AreaDataHnd, SWORD Position)
{
SWORD offset,len;
ListHandle list;
TEHandle text;
Cell CurrCell;
Ptr TextPtr;
CurrCell.v = 0;
CurrCell.h = 0;
list = (*AreaDataHnd)->ListHnd;
text = (*AreaDataHnd)->TextTEHnd;
while(LGetSelect(true, &CurrCell,list))
LSetSelect(false,CurrCell,list);
if ((Position>0) && (Position <=(*list)->dataBounds.bottom))
{
CurrCell.v = Position-1;
LSetSelect(true,CurrCell,list);
LAutoScroll(list);
LGetCellDataLocation(&offset,&len,CurrCell,list);
TextPtr = NewPtr(len+1);
if((*AreaDataHnd)->Flags.Active)
TEDeactivate(text);
LGetCell(TextPtr,&len,CurrCell,list);
TESetText(TextPtr, (long) len, text);
DisposePtr(TextPtr);
if((*AreaDataHnd)->Flags.Active)
{
TESetSelect(0,32767,text);
TEActivate(text);
}
}
else
TESetText(NULL,0,text); // wipe out the text if there's no element
InvalRect(&(*AreaDataHnd)->AreaRect);
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_GetLstPos
//
//---------------------------------------------------------------------------------
SLONG CB_GetLstPos(AreaHnd AreaDataHnd)
{
Cell CurrCell;
CurrCell.v = 0;
CurrCell.h = 0;
if(LGetSelect(true,&CurrCell,(*AreaDataHnd)->ListHnd))
return (SWORD)CurrCell.v+1;
else
return 0;
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetTxt
//
//---------------------------------------------------------------------------------
void CB_SetTxt(AreaHnd AreaDataHnd, TextBlock* TextText)
{
GrafPtr savePort;
if(TextText->fData != NULL)
{
HLock((Handle)(TextText->fData));
TESetText(*(TextText->fData), (long) TextText->fSize, (*AreaDataHnd)->TextTEHnd);
HUnlock((Handle)(TextText->fData));
}
else
TESetText(NULL,0,(*AreaDataHnd)->TextTEHnd);
if((*AreaDataHnd)->Flags.Active)
TESetSelect(0,32767,(*AreaDataHnd)->TextTEHnd);
GetPort(&savePort);
SetPort((*AreaDataHnd)->AreaGrafPort);
InvalRect(&(*AreaDataHnd)->AreaRect);
SetPort(savePort);
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_GetTxt
//
//---------------------------------------------------------------------------------
void CB_GetTxt(AreaHnd AreaDataHnd, TextBlock* TextText)
{
TextText->fSize = (*((*AreaDataHnd)->TextTEHnd))->teLength;
SetHandleSize(TextText->fData,TextText->fSize);
HLock((*((*AreaDataHnd)->TextTEHnd))->hText);
HLock(TextText->fData);
BlockMove(*((*((*AreaDataHnd)->TextTEHnd))->hText),*(TextText->fData),TextText->fSize);
HUnlock(TextText->fData);
HUnlock((*((*AreaDataHnd)->TextTEHnd))->hText);
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetModified
//
//---------------------------------------------------------------------------------
void CB_SetModified(AreaHnd AreaDataHnd, SWORD Modified)
{
(*AreaDataHnd)->Flags.Modified = (Modified != 0);
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_GetModified
//
//---------------------------------------------------------------------------------
SLONG CB_GetModified(AreaHnd AreaDataHnd)
{
if((*AreaDataHnd)->Flags.Modified)
return 1;
else
return 0;
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetEnabled
//
//---------------------------------------------------------------------------------
void CB_SetEnabled(AreaHnd AreaDataHnd, SWORD Enabled)
{
if ((SWORD)(*AreaDataHnd)->Flags.Enabled != Enabled)
{
(*AreaDataHnd)->Flags.Enabled = (Enabled != 0);
InvalRect(&((*AreaDataHnd)->AreaRect));
}
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_GetEnabled
//
//---------------------------------------------------------------------------------
SLONG CB_GetEnabled(AreaHnd AreaDataHnd)
{
if((*AreaDataHnd)->Flags.Enabled)
return 1;
else
return 0;
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_SetHilite
//
//---------------------------------------------------------------------------------
void CB_SetHilite(AreaHnd AreaDataHnd, SWORD Start, SWORD End)
{
TESetSelect((long)Start,(long)End,(*AreaDataHnd)->TextTEHnd);
InvalRect(&((*AreaDataHnd)->AreaRect));
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_GetHilite
//
//---------------------------------------------------------------------------------
void CB_GetHilite(AreaHnd AreaDataHnd, SWORD* Start, SWORD* End)
{
*Start = ((*((*AreaDataHnd)->TextTEHnd))->selStart);
*End = ((*((*AreaDataHnd)->TextTEHnd))->selEnd);
}
//---------------------------------------------------------------------------------
//
// FUNCTION: CB_GetFontNum
//
//---------------------------------------------------------------------------------
SLONG CB_GetFontNum(UBYTE* FontName)
{
SWORD FontNum;
SLONG LongFontNum;
GetFNum((ConstStr255Param) FontName,&FontNum);
LongFontNum = FontNum;
return (LongFontNum);
}
//---------------------------------------------------------------------------------
//
// FUNCTION: ListSynchronize
//
//---------------------------------------------------------------------------------
void ListSynchronize(AreaPtr AreaDataPtr)
{
ValueBlock ArrValBlock;
ParameterBlock block;
SLONG ListElems,index;
ListHandle List;
XHANDLE ArrDataHnd;
TextPtr ArrElemPtr;
Cell whichCell;
block.fH = (XHANDLE)&ArrValBlock;
Pstrcpy(AreaDataPtr->ListArrName,block.fName);
if(AreaDataPtr->Flags.InterprocArr)
{
CALL4D(kEX_GET_GLOBALVAR,&block);
}
else
CALL4D(kEX_GET_VARIABLE,&block);
AreaDataPtr->ArrElems = ArrValBlock.uValue.fArray.fSize;
ArrDataHnd = ArrValBlock.uValue.fArray.fData;
List = AreaDataPtr->ListHnd;
if(List)
{
ListElems = (*List)->dataBounds.bottom;
if(AreaDataPtr->ArrElems<ListElems)
LDelRow(ListElems-AreaDataPtr->ArrElems,1,List);
else if(AreaDataPtr->ArrElems>ListElems)
LAddRow(AreaDataPtr->ArrElems-ListElems,1,List);
HLock((Handle)ArrDataHnd);
whichCell.h = 0;
for (index = 1; index<=AreaDataPtr->ArrElems; index++)
{
ArrElemPtr = NthTElemAdr(ArrDataHnd,index);
whichCell.v = index-1; // Cells are zero-relative
HLock((Handle)(ArrElemPtr->fData));
LSetCell(*(ArrElemPtr->fData),ArrElemPtr->fSize,whichCell,List);
if(MemError())
SysBeep(10);
HUnlock((Handle)(ArrElemPtr->fData));
}
HUnlock((Handle)ArrDataHnd);
}
}